package com.work.mvc.view;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.vaadin.data.Property;
import com.work.mvc.view.table.property.*;
import com.work.util.AppUtils;

public class TablePropertyFormat {
	public static String formatMontWorktimePropertyValue(Object rowId, Object colId, Property<?> property)
	{
		if (property.getType() == Date.class) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			return df.format((Date) property.getValue());
		} else if (property.getType() == Time.class) {
			if (property.getValue() != null) {
				return property.getValue().toString();
			}
		} else if (colId.equals(MonthWorkTimeProperty.TOTAL) || colId.equals(MonthWorkTimeProperty.OVERTIME)) {
			return AppUtils.convertMinutesToTimeString((String) property.getValue());
		}

		return null;
	}

	public static String formatSummaryWorktimePropertyValue(Object rowId, Object colId, Property<?> property)
	{
		if (colId.equals(SummaryWorkTimeProperty.WORKTIME_MINUTES)
				|| colId.equals(SummaryWorkTimeProperty.OVERTIME_MINUTES)
				|| colId.equals(SummaryWorkTimeProperty.ESTIMATED_MINUTES)) {
			return AppUtils.convertMinutesToTimeString((String) property.getValue());
		}

		return null;
	}
}
